home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / headers / application.h < prev    next >
Encoding:
Text File  |  2000-09-28  |  9.6 KB  |  326 lines

  1. /*
  2.     File:        Application.h
  3.  
  4.     Contains:    TApplication is an abstract base class, TBKApplication is a background only application class,
  5.                   TGUIApplication is a window-based user application class. TQTApplication is a QuickTime aware application
  6.                   class, TGXApplication is a Quickdraw GX aware application class. Finally TQTAndGXApplication 
  7.                  handles both QX and QT application work.
  8.                   Application.h contains application level classes for building the wire for an application framework.
  9.  
  10.     Written by:     
  11.  
  12.     Copyright:    Copyright Â© 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  13.  
  14.                 You may incorporate this Apple sample source code into your program(s) without
  15.                 restriction. This Apple sample source code has been provided "AS IS" and the
  16.                 responsibility for its operation is yours. You are not permitted to redistribute
  17.                 this Apple sample source code as "Apple sample source code" after having made
  18.                 changes. If you're going to re-distribute the source, we require that you make
  19.                 it clear in the source that the code was descended from Apple sample source
  20.                 code, but that you've made changes.
  21.  
  22.     Change History (most recent first):
  23.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  24.                 
  25.  
  26. */
  27. // Declare label for this header file
  28. #ifndef _APPLICATION_
  29. #define _APPLICATION_
  30.  
  31.  
  32. #ifndef _DTSCPLUSLIBRARY_
  33. #include "DTSCPlusLibrary.h"
  34. #endif
  35.  
  36. //    Toolbox Interfaces
  37. #ifndef __QUICKDRAW__
  38. #include <Quickdraw.h>
  39. #endif
  40.  
  41. #ifndef __EVENTS__
  42. #include <Events.h>
  43. #endif
  44.  
  45. #ifndef __OSEVENTS__
  46. #include <OSEvents.h>
  47. #endif
  48.  
  49. #ifndef __MEMORY__
  50. #include <Memory.h>
  51. #endif
  52.  
  53. #ifndef __WINDOWS__
  54. #include <Windows.h>
  55. #endif
  56.  
  57. #ifndef __DESK__
  58. #include <Desk.h>
  59. #endif
  60.  
  61. #ifndef __FONTS__
  62. #include <Fonts.h>
  63. #endif
  64.  
  65. #ifndef __TOOLUTILS__
  66. #include <ToolUtils.h>
  67. #endif
  68.  
  69. #ifndef __DIALOGS__
  70. #include <Dialogs.h>
  71. #endif
  72.  
  73. #ifndef __MENUS__
  74. #include <Menus.h>
  75. #endif
  76.  
  77. #ifndef __TEXTEDIT__
  78. #include <TextEdit.h>
  79. #endif
  80.  
  81. #ifndef __APPLEEVENTS_
  82. #include <AppleEvents.h>
  83. #endif
  84.  
  85. #ifndef __RESOURCES__
  86. #include <Resources.h>
  87. #endif
  88.  
  89. #ifndef __DISKINIT__
  90. #include <DiskInit.h>
  91. #endif
  92.  
  93. // DTS Library headers
  94. #ifndef _WINDOW_
  95. #include "Window.h"
  96. #endif
  97.  
  98. #ifndef _APPLEEVENT_
  99. #include "AppleEvent.h"
  100. #endif
  101.  
  102. #include "Menu.h"
  103.  
  104.  
  105. #include <AERegistry.h>
  106.  
  107.  
  108. #include "ApplicationResources.h"
  109. #include "CollectionClasses.h"
  110.  
  111. // GLOBAL INTERNAL STRUCTURES
  112.  
  113. struct AEEventTable
  114. {                                                // AppleEvent record
  115.     OSType theClass;
  116.     OSType theID;
  117.     long theValue;
  118. };
  119.  
  120.  
  121. typedef AEEventTable* AEEventTablePtr;
  122.  
  123. // _________________________________________________________________________________________________________ //
  124. //    TApplication Interface.
  125.  
  126. class TApplication
  127. // The TApplication is the base class for Application classes. It contains the basic behavior
  128. // for any application work. Note that it's an abstract class.
  129. {
  130. public:
  131.     // TYPEDEFS AND ENUMS
  132.     enum EConstants
  133.     {
  134.         kForgroundSleepValue = 0, kSuspendResumeMessage = 1, kResumeMask = 1, kHighByte = 24, kBackgroundSleepValue = 60
  135.     };
  136.  
  137.  
  138.     enum EState
  139.     {
  140.         kInit = 1, kRun, kQuit
  141.     };
  142.  
  143.     // CONSTRUCTORS AND DESTRUCTORS
  144.     TApplication();                                // default constructor
  145.     virtual~ TApplication();                    // default destructor
  146.  
  147.     // MAIN INTERFACE
  148.     virtual void InitializeMemory();            // initialize our memory needs
  149.     virtual void InitializeToolbox() = 0;        // initialize the toolbox
  150.  
  151.     // EVENT AND CONTROL METHODS
  152.     virtual void DoNextEvent();                    // handle the incoming events
  153.     virtual void DoEventLoop(){};                // handle the actual event dispatching
  154.     virtual void DoHighLevelEvent();            // handle high level events
  155.  
  156.     virtual void Start();                        // start the application and let it run
  157.     virtual void DoIdle() = 0;                    // call idle handler
  158.     virtual void Quit();                        // quit the application 
  159.     virtual void DoCommand(long     /*command*/){};// handle commands
  160.  
  161.     // CORE AE HANDLER METHODS
  162.     virtual void InstallAEHandler();            // install our AE dispatcher
  163.     virtual void DispatchAppleEvents(AppleEvent* in,
  164.                                      AppleEvent* out,
  165.                                      long Command);// Dispatch incoming Apple Events in the framework
  166.  
  167.     virtual OSErr HandleQuit(AppleEvent* in,
  168.                              AppleEvent* out,
  169.                              long refCon);        // handle the quit AE
  170.     virtual OSErr HandleOpen(AppleEvent* in,
  171.                              AppleEvent* out,
  172.                              long refCon);        // handle the open AE
  173.     virtual OSErr HandleOpenDocuments(AppleEvent* in,
  174.                                       AppleEvent* out,
  175.                                       long refCon);// handle the open document AE
  176.     virtual OSErr HandlePrint(AppleEvent* in,
  177.                               AppleEvent* out,
  178.                               long refCon);        // handle the print command
  179.  
  180.     // STATE CHANGE METHODS
  181.     virtual void SetState(TApplication::EState theState);// change the state of the application FSM
  182.  
  183.     // FIELDS
  184. protected:
  185.     RgnHandle fSleepRegion;                        // our sleep region (for possible mouse movements)
  186.     long fSleepValue;                            // defined sleep value for WaitNextEvent
  187.     EventRecord fEventRecord;                    // current event record
  188.     short fEventMask;                            // our eventMask
  189.     short fMoreMasters;                            // amount of MoreMaster calls
  190.     TAppleEvent fMessenger;                        // our AE posting system
  191.     EState fState;                                // internal state of the TApplication
  192.     OSErr fError;                                // latest error
  193. };
  194.  
  195.  
  196. // _________________________________________________________________________________________________________ //
  197. //    TBKApplication Interface.
  198.  
  199. class TBKApplication : public TApplication
  200. // The TBKApplication is the base class for background only/faceless applications. It provides
  201. // the basic skeleton for building such applications.
  202. {
  203. public:
  204.     // CONSTRUCTORS AND DESTRUCTORS
  205.     TBKApplication();
  206.     virtual~ TBKApplication();
  207. };
  208.  
  209.  
  210. // _________________________________________________________________________________________________________ //
  211. //    TGUIApplication Interface.
  212.  
  213. class TGUIApplication : public TApplication
  214. // The TGUIApplication is the base class for writing window/menu based user interaction applications.
  215. {
  216. public:
  217.     // CONSTRUCTORS AND DESTRUCTORS
  218.     TGUIApplication();                            // default constructor
  219.     virtual~ TGUIApplication();                    // default destructor
  220.  
  221.     // MAIN INTERFACE
  222.     // CONTROL
  223.     virtual void InitializeToolbox();            // initialize the toolbox
  224.     virtual void Start();                        // handle the cursor before calling inherited Start
  225.     virtual void DoEventLoop();                    // handle the actual event dispatching
  226.  
  227.     // SYSTEM
  228.     virtual void DoIdle();                        // handle idle time
  229.     virtual void DoSystemTime();                // handle DA time
  230.     virtual void DoDiskEvent();                    // handle disk insertion events
  231.     virtual void DispatchAppleEvents(AppleEvent* in,
  232.                                      AppleEvent* out,
  233.                                      long command);
  234.  
  235.     // GENERAL WINDOW EVENTS
  236.     virtual void DoWindowUpdate();                // handle window updating
  237.     virtual void DoDragWindow();                // handle inDrag events
  238.     virtual void DoGoAwayWindow();                // handle doGoAway events
  239.     virtual void DoInWindowContent();            // handle window mouse clicks
  240.  
  241.     // MENU EVENTS
  242.     virtual void DoMenuCommand();                // handle menu command
  243.     virtual void DoInternalMenus(long command);    // handle internal menus (Apple)
  244.     virtual void DoCommand(long command);        // handle commands related to default GUI
  245.     virtual long CalculateMenuCommand(long menuentry);// calculate the menu command
  246.  
  247.     // AE HANDLING
  248.     virtual OSErr HandleOpen(AppleEvent* in,
  249.                              AppleEvent* out,
  250.                              long refCon);        // OVERRIDE - handle the open AE
  251.  
  252.     // DOCUMENT METHODS
  253.     virtual void DoCreateDocument();            // create our document (default one window)
  254.     virtual void DoCreateDocument(short windowID);// create our document from a resource (default one window)
  255.     virtual void AddDocument(TWindow* theDocument);// add the document to the list of known ones
  256.  
  257.     // USER INTERACTIONS
  258.     virtual void Draw();                        // draw in the main window
  259.     virtual void DoClick();                        // handle a click inside a window
  260.     virtual void AdjustUserInterface(){};        // adjust the user interface based on state changes
  261.     virtual void DoAboutBox();                    // present our About… box
  262.     virtual void DoHelp();                        // a hook to a possible outside help system
  263.  
  264.     // FIELDS
  265. protected:
  266.     CursHandle fCursHandle;                        // current cursor selected
  267.     TWindow* fDocument;                            // our only window/document (create list of windows later)
  268.     WindowPtr fCurrentWindow;                    // the current window attached to the event
  269.     short fWindowNum;                            // amount of windows
  270.     long fMenuResult;                            // value received from menu
  271. };
  272.  
  273.  
  274. // _________________________________________________________________________________________________________ //
  275. //    TQTApplication Interface.
  276.  
  277. class TQTApplication : public TGUIApplication
  278. // The TQTApplication is the base class for writing window/menu based user interaction applications
  279. // that also handles QuickTime calls.
  280. {
  281. public:
  282.     // CONSTRUCTORS AND DESTRUCTORS
  283.     TQTApplication();
  284.     virtual~ TQTApplication();
  285. };
  286.  
  287.  
  288. // _________________________________________________________________________________________________________ //
  289. //    TGXApplication Interface.
  290.  
  291. class TGXApplication : public TGUIApplication
  292. // The TGXApplication is the base class for writing window/menu based user interaction applications
  293. // that also handles Quickdraw GX calls.
  294. {
  295. public:
  296.     // CONSTRUCTORS AND DESTRUCTORS
  297.     TGXApplication();
  298.     virtual~ TGXApplication();
  299. };
  300.  
  301.  
  302. // _________________________________________________________________________________________________________ //
  303. //    TQTAndGXApplication Interface.
  304.  
  305. class TQTAndGXApplication : public TGUIApplication
  306. // The TGXApplication is the base class for writing window/menu based user interaction applications
  307. // that handles both Quickdraw GX and QuickTime calls.
  308. {
  309. public:
  310.     // CONSTRUCTORS AND DESTRUCTORS
  311.     TQTAndGXApplication();
  312.     virtual~ TQTAndGXApplication();
  313. };
  314.  
  315.  
  316. #endif
  317.  
  318. // _________________________________________________________________________________________________________ //
  319.  
  320.  
  321. /*    Change History (most recent last):
  322.   No        Init.    Date        Comment
  323.   1            khs        11/6/92        New file
  324.   2            khs        1/14/92        Cleanup
  325. */
  326.